/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import dto.Conferenceitem;
import dto.Itemauthors;
import dto.User;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Timmy
 */
public class ConferenceModel {
    public static final int PaperPrensentation = 1; 
    public static final int Workshop = 2; 
    public static final int DoctoralSymposium = 4; 
    public static final int Tutorial = 8;
    
    public static final int NotAssigned = 0; 
    public static final int Assigned = 1; 
    public static final int Reviewd = 2; 
    
    public static boolean IsTypeAvailable(int availableType,int checkingType)
    {
        return (checkingType & availableType) == checkingType; 
    }
    
    public static String GetConferenceItemType(int type)
    {
        switch (type)
        {
            case ConferenceModel.PaperPrensentation : return "Paper Presentation";
            case ConferenceModel.Workshop : return "Work Shop";
            case ConferenceModel.DoctoralSymposium : return "Doctoral Symposium";
            case ConferenceModel.Tutorial : return "Tutorial";
        }
        return "Unknown";
    }
    
    public static Integer GetConferenceItemValue(String type)
    {
        switch(type)
        {
            case "Paper Presentation" : return ConferenceModel.PaperPrensentation;
            case "Work Shop" : return ConferenceModel.Workshop;
            case "Doctoral Symposium" : return ConferenceModel.DoctoralSymposium;
            case "Tutorial" : return ConferenceModel.Tutorial;
        }
        return 0 ;
    }
    
    public static String GetConferenceItemReviewStatus(int type)
    {
        switch (type)
        {
            case ConferenceModel.NotAssigned : return "Not Assigned";
            case ConferenceModel.Assigned : return "Assigned";
            case ConferenceModel.Reviewd : return "Reviewed";
        }
        return "Unknown";
    }
    
    public static AuthorModel ConverAuthorModel(Itemauthors authos)
    {
        AuthorModel model = new AuthorModel();
        model.setAuthorName(authos.getId().getUserName());
        model.setIsFirstAuthor(authos.getIsFirstAuthor());
        return model; 
    }
    
    public static List<AuthorModel> ConverAuthorModelList(List<Itemauthors> authors)
    {
        List<AuthorModel> models = new ArrayList<>();
        for (Itemauthors auth: authors)
        {
            models.add(ConferenceModel.ConverAuthorModel(auth));
        }
        return models; 
    }
    
    //Added by Ei Chaw.......Pls change accrodingly
    public static List<ReviewerModel> ConvertReviewerModelList(List<User> users){
        List<ReviewerModel> models=new ArrayList<>();
        for(User user:users){
            models.add(ConferenceModel.ConverReviewerModel(user));
        }
        return models;
    }   
    //Added by Ei Chaw.......Pls change accrodingly
    public static ReviewerModel ConverReviewerModel(User user){
        ReviewerModel model=new ReviewerModel();
        model.setUsername(user.getUserName());
        return model;
    }
    
    public static ConferenceListDisplayModel ConverModel(Conferenceitem item)
    {
        ConferenceListDisplayModel displayModel = new ConferenceListDisplayModel();
        displayModel.setItemName(item.getId().getItemName());
        displayModel.setItemDescription(item.getItemDescription());
        displayModel.setConferenceName(item.getId().getConferenceName());
        displayModel.setFilePath(item.getFilePath());
        displayModel.setCategory(ConferenceModel.GetConferenceItemType(item.getCategory()));
        displayModel.setStatus(ConferenceModel.GetConferenceItemReviewStatus(item.getStatus()));
        if (item.getIsBlindReivew())
        {
            displayModel.setIsBlindReview("True");
        }
        else 
        {
            displayModel.setIsBlindReview("False");
        }
        DecimalFormat df=new DecimalFormat("#.00"); 
        String price = df.format(item.getSellPrice());
        displayModel.setSellPrice(df.format(item.getSellPrice()));
        return displayModel; 
    }
    
    public static  List<ConferenceListDisplayModel> ConverModelList(List<Conferenceitem> items)
    {
        List<ConferenceListDisplayModel> models = new ArrayList<>();
        for(Conferenceitem m : items)
        {
            models.add(ConferenceModel.ConverModel(m));
        }
        return models;
    }
}
